package com.siqi.hr.system.custom.entity;

import org.springframework.jdbc.core.RowMapper;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 数据字典对象(主要存单选按钮，下拉框，复选框)
 * @author    xiaogq
 * Created by xiaogoingqin on 2016/7/24.
 */
public class SelectBox implements Serializable{

    /**
     * 数据字段id
     */
    private Integer id;

    /**
     * 数据字段名称
     */
    private String name;

    /**
     * 所属实体id
     */
    private int entityId;

    /**
     * 所属字段id
     */
    private FieldRecord field;

    /**
     * 描述
     */
    private String valsComment;

    /**
     * 是否有默认值
     */
    private boolean defaultValue;

    /**
     * 排序字段
     */
    private int position;

    /**
     * 是否是系统字典字段(0:否，1：是默认值为0)
     */
    private boolean sysRecord;

    /**
     * 注册字段英文名称
     */
    private String fieldName;

    /**
     * 引用下拉级联字段id
     */
    private Integer restricter;

    /**
     * 引用下拉级联字段名称
     */
    private String restricterName;

    public SelectBox() {
    }

    public SelectBox(Integer id, String name) {
        this.id = id;
        this.name = name;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getEntityId() {
        return entityId;
    }

    public void setEntityId(int entityId) {
        this.entityId = entityId;
    }

    public FieldRecord getField() {
        return field;
    }

    public void setField(FieldRecord field) {
        this.field = field;
    }

    public String getValsComment() {
        return valsComment;
    }

    public void setValsComment(String valsComment) {
        this.valsComment = valsComment;
    }

    public boolean isDefaultValue() {
        return defaultValue;
    }

    public void setDefaultValue(boolean defaultValue) {
        this.defaultValue = defaultValue;
    }

    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public boolean isSysRecord() {
        return sysRecord;
    }

    public void setSysRecord(boolean sysRecord) {
        this.sysRecord = sysRecord;
    }

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public Integer getRestricter() {
        return restricter;
    }

    public void setRestricter(Integer restricter) {
        this.restricter = restricter;
    }

    public String getRestricterName() {
        return restricterName;
    }

    public void setRestricterName(String restricterName) {
        this.restricterName = restricterName;
    }

    public static class FullSelectBox extends SelectBox implements RowMapper<SelectBox> {
        public SelectBox mapRow(ResultSet rs, int index) throws SQLException {
            SelectBox sb = new SelectBox();
            sb.setId(rs.getInt("id"));
            sb.setName(rs.getString("name"));
            sb.setEntityId(rs.getInt("entityId"));
            sb.setField(new FieldRecord(rs.getInt("field_id")));
            sb.setValsComment(rs.getString("vals_comment"));
            sb.setDefaultValue(rs.getBoolean("default_value"));
            sb.setSysRecord(rs.getBoolean("sys_record"));
            return sb;
        }
    }

    public static class getSelectBoxNameAndFieldName extends SelectBox implements RowMapper<SelectBox> {
        public SelectBox mapRow(ResultSet rs, int index) throws SQLException {
            SelectBox sb = new SelectBox();
            sb.setId(rs.getInt("id"));
            sb.setName(rs.getString("name"));
            return sb;
        }
    }

    public static class getSelectBoxInfoByFieldId extends SelectBox implements RowMapper<SelectBox> {
        public SelectBox mapRow(ResultSet rs, int index) throws SQLException {
            SelectBox sb = new SelectBox();
            sb.setFieldName(rs.getString("fieldName"));
            sb.setId(rs.getInt("id"));
            sb.setName(rs.getString("name"));
            return sb;
        }
    }

}
